home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-06-17 | 2.2 KB | 133 lines | [TEXT/CWIE] |
- // FileOutStream.cp
-
- #ifndef FileOutStream_h
- #include "FileOutStream.h"
- #endif
- #ifndef ConstData_h
- #include "ConstData.h"
- #endif
- #ifndef FileWritingPath_h
- #include "FileWritingPath.h"
- #endif
- #ifndef __DEVICES__
- #include <Devices.h>
- #endif
-
- FileOutStream::FileOutStream()
- {
- ioParam.ioPosMode = fsFromStart;
- }
-
- Task *FileOutStream::NonblockingWrite( ConstData buffer )
- {
- return BlockingWrite( buffer );
- }
-
- Task *FileOutStream::BlockingWrite( ConstData buffer )
- {
- Assert( !Running() );
-
- ioParam.ioBuffer = reinterpret_cast<Ptr>(
- const_cast<uint8 *>( buffer.Start() ) );
- ioParam.ioReqCount = buffer.Length();
- flushing = false;
-
- return this;
- }
-
- Task *FileOutStream::FlushingTask()
- {
- flushing = true;
- return this;
- }
-
- void FileOutStream::Launch()
- {
- Assert( !Running() );
-
- if ( flushing )
- PBFlushFileAsync( this );
- else
- PBWriteAsync( this );
- }
-
- void FileOutStream::Kill()
- {
- }
-
- void FileOutStream::AtCompletion()
- {
- Assert( !Running() );
-
- if ( !flushing )
- ReportWrite( ioParam.ioActCount );
-
- if ( ioParam.ioResult != noErr )
- ReportFailure();
- }
-
- void FileOutStream::SetFile( const FileWritingPath& path,
- uint32 position )
- {
- Assert( !Running() );
- Assert( path.IsOpen() );
-
- ioParam.ioRefNum = path.RefNum();
- ioParam.ioPosOffset = position;
- Reset();
- }
-
- void FileOutStream::ClearFile()
- {
- Assert( !Running() );
- ioParam.ioRefNum = 0;
- Reset();
- }
-
- uint32 FileOutStream::Position() const
- {
- Assert( !Running() );
- Assert( HasFile() );
- return ioParam.ioPosOffset;
- }
-
- void FileOutStream::SetPosition( uint32 p )
- {
- Assert( !Running() );
- Assert( HasFile() );
- ioParam.ioPosOffset = p;
- Reset();
- }
-
- void FileOutStream::SuggestCaching()
- {
- Assert( !Running() );
- ioParam.ioPosMode |= cacheBit;
- ioParam.ioPosMode &= ~noCacheBit;
- }
-
- void FileOutStream::SuggestNoCaching()
- {
- Assert( !Running() );
- ioParam.ioPosMode |= noCacheBit;
- ioParam.ioPosMode &= ~cacheBit;
- }
-
- void FileOutStream::ClearCachingSuggestion()
- {
- Assert( !Running() );
- ioParam.ioPosMode &= ~( noCacheBit | cacheBit );
- }
-
- void FileOutStream::VerifyWrites()
- {
- Assert( !Running() );
- ioParam.ioPosMode |= rdVerify;
- }
-
- void FileOutStream::DontVerifyWrites()
- {
- Assert( !Running() );
- ioParam.ioPosMode &= ~rdVerify;
- }
-